home *** CD-ROM | disk | FTP | other *** search
- Path: lade.news.pipex.net!pipex!dircon!usenet
- From: sridgway@dircon.co.uk (Steven Ridgway)
- Newsgroups: comp.lang.c
- Subject: Re: ?Help - struct array of strings
- Date: Mon, 11 Mar 1996 22:11:36 GMT
- Organization: Direct Connection
- Message-ID: <4i28ln$2i0@newsgate.dircon.co.uk>
- References: <4hvpgp$gu7@ftp.netgate.net>
- NNTP-Posting-Host: gw4-129.pool.dircon.co.uk
- X-Newsreader: Forte Free Agent 1.0.82
-
- Tamara Johnson <malihini@netgate.net> wrote:
-
- >/*
- > program to enter author(s), title(s)
- > then display entries.
- > why is printf displaying strange things?
- > (see output at end)
- >*/
-
- >#include <stdlib.h>
- >#include <stdio.h>
- >#include <conio.h>
- >#include <string.h>
-
- >#define MAX 5
-
- >struct catalog{
- > char name[80]; /* author name */
- > char title[80]; /* title */
- >}cat[80];
-
- >void main()
-
- >{
- >int i;
-
- >for(i=0;i<MAX;i++)
- > {
- > printf("Enter author name (ENTER to quit); ");
- > gets(cat[i].name);
- > if(!*cat[i].name) break;
- > printf("Enter title: ");
- > gets(cat[i].title);
- > }
- >for(i=0;i<MAX;i++)
- > printf("%c %c\n", cat[i].name, cat[i].title);
- >}
- >/*
- >output;
-
- >Enter author name (ENTER to quit); tom
- >Enter title: pickled peppers
- >Enter author name (ENTER to quit); sam
- >Enter title: hop on pop
- >Enter author name (ENTER to quit);
- >` t
- >Ω ú
- >_ -
- >+ _
- > ╢
- >*/
-
- Hi,
-
- In your printf try using %s rather than %c.
- %c means print a char, but you are passing a string (ie a pointer), so
- you see the first byte of your pointer.
-
- steven ridgway (sridgway@dircon.co.uk)
-
-